package main;

public class identifyOS {

	/**
	 * Identify the OS
	 * 
	 * @return 0:Windows, 1:Linux, 2:Mac, 3: Solaris, -1:Not Supported
	 */
	public int identifyOS() {
		if (isWindows()) {
			//System.out.println("This is Windows");
			return 0;
		} else if (isUnix()) {
			//System.out.println("This is Unix or Linux");
			return 1;
		} else if (isMac()) {
			System.out.println("This is Mac");
			return 2;
		} else if (isSolaris()) {
			System.out.println("This is Solaris");
			return 3;
		} else {
			System.out.println("Your OS is not support!!");
			return -1;
		}
	}

	private boolean isWindows() {
		String os = System.getProperty("os.name").toLowerCase();
		// windows
		return (os.indexOf("win") >= 0);
	}

	private boolean isMac() {
		String os = System.getProperty("os.name").toLowerCase();
		// Mac
		return (os.indexOf("mac") >= 0);
	}

	private boolean isUnix() {
		String os = System.getProperty("os.name").toLowerCase();
		// linux or unix
		return (os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0);
	}

	private boolean isSolaris() {
		String os = System.getProperty("os.name").toLowerCase();
		// Solaris
		return (os.indexOf("sunos") >= 0);
	}
}
